﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using coffeeshop.coffeeDataSetTableAdapters;

namespace coffeeshop.Models
{
    public class OrderTable
    {
        public int TableOrderId { get; set; }
        public Global.TableStatus Status { get; set; }
        public string TableOrderName { get; set; }
        public Boolean IsActive { get; set; }
   
        private static OrderTableTableAdapter objDt = new OrderTableTableAdapter();

        public OrderTable() { }
        public OrderTable(int myTableOrderId) { TableOrderId = myTableOrderId; }

        public static coffeeDataSet.OrderTableDataTable CountActiveTable()
        {
            coffeeDataSet.OrderTableDataTable objTbl = new coffeeDataSet.OrderTableDataTable();
            objTbl = objDt.GetActiveTables(true); 
            return objTbl;
        }

        public static OrderTable GetTableOrderById(int v_TableOrderId)
        {
            OrderTable objOrderTable= new OrderTable();
            coffeeDataSet.OrderTableDataTable objTableData = new coffeeDataSet.OrderTableDataTable();
            objTableData = objDt.GetDataBy(v_TableOrderId);

            if (objTableData.Any())
            {
                objOrderTable.TableOrderId = (int)objTableData.Rows[0]["OrderTableId"];
                objOrderTable.TableOrderName = (string)objTableData.Rows[0]["Name"];
                objOrderTable.Status = (Global.TableStatus)objTableData.Rows[0]["Status"];
                objOrderTable.IsActive = (bool)objTableData.Rows[0]["IsActive"];
            }
            return objOrderTable;
        }

        public bool updateOrderTable()
        {           
            try
            {
                int intResult = objDt.UpdateOrderTable(TableOrderName, IsActive, (int)Status, TableOrderId);
                return intResult == 1;                
            }
            catch
            {
                return false;
            }
        }
    }
}
